<?php
use yii\widgets\LinkPager;
use common\models\Country;
?>

<div class="container">
    <div class="row ">
        <!-- biaoge 立项审批-->
        <?PHP
        if(count($data)>0){
            ?>
            <div class="clearfix myApproval-table-wrap" style=" border: 1px solid #eeeeee; overflow: hidden;">
                <table class="myApproval-table" style="border: none!important;">
                    <thead style="" class="thead-normal">
                    <tr>
                        <th class="text-center">序号</th>
                        <th class="text-center">资产包编号</th>
                        <th class="text-center">资产包名称 </th>
                        <!--<th class="text-center">本金 </th>-->
                        <th class="text-center">省份地区</th>
                        <th class="text-center">申请人</th>
                        <th class="text-center">申请立项理由</th>
                        <th class="text-center">申请时间</th>
                        <th class="text-center">审批结果</th>
                        <th class="text-center">审批意见</th>
                        <th class="text-center">操作</th>
                    </tr>
                    </thead>
                    <thead style="" class="thead-fixed">
                    <tr>
                        <th class="text-center">序号</th>
                        <th class="text-center">资产包编号</th>
                        <th class="text-center">资产包名称 </th>
                        <!--<th class="text-center">本金 </th>-->
                        <th class="text-center">省份地区</th>
                        <th class="text-center">申请人</th>
                        <th class="text-center">申请立项理由</th>
                        <th class="text-center">申请时间</th>
                        <th class="text-center">审批结果</th>
                        <th class="text-center">审批意见</th>
                        <th class="text-center">操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    <?PHP
                    $i = 0;
                    $audit_result=Yii::$app->params['audit_result'];
                    $list = Country::getTitleList();
                    foreach ($data as $value) {//'result','package.provinceName','package.cityName','user'
                    // 本金<td title="'.$value['principal'].'"><span class="txt-cut">'.$value['principal'].'</span></td>
                        $str='审批完成';
                        if($value['result']==1){
                            $str='<span class="txt-cut approval" style="cursor:pointer!important" application_id="'.$value['application_id'].'" result_id="'.$value['id'].'" >审批</span>';
                        }
                        //显示多城市
                        $countrylist='';
                        if ($value['city'] != '') {
                            $arr = explode(',', $value['city']);
                            $array = array();
                            if (!empty($arr)) {
                                foreach ($arr as $val) {
                                    if ($val > 0) {
                                        $countrylist.=$countrylist?','.$list[(int)$val]:$list[(int)$val];
                                    }
                                }
                            }
                        }
                        $i++;
                        echo ' <tr class="text-left" >
                                            <td class="clearfix text-center" >'.$i.'</td>
                                            <td title="'.$value['code'].'"><span class="txt-cut">'.$value['code'].'</span></td>
                                            <td title="'.$value['title'].'">
                                            	<a target="_blank" href="/package/detail-info?packageid='.$value['package_id'].'"><span class="txt-cut" style="color:#2096f1;cursor:pointer;">'.$value['title'].'</span></a>
                                            	</td>
                                            
                                            <td title="'.$value['provinceName'].$countrylist.'"><span class="txt-cut">'.$value['provinceName'].$countrylist.'</span></td>
                                            <td title="'.$value['realname'].'"><span class="txt-cut">'.$value['realname'].'</span></td>
                                            <td title="'.$value['reason'].'"><span class="txt-cut">'.$value['reason'].'</span></td>
                                            <td title="'.$value['applied_at'].'"><span class="txt-cut">'.$value['applied_at'].'</span></td>
                                            <td title="'.$audit_result[$value['result']].'"><span class="txt-cut">'.$audit_result[$value['result']].'</span></td>
                                            <td title="'.$value['note'].'"><span class="txt-cut">'.$value['note'].'</span></td>
                                            <td title="">'.$str.'</td>
                                        </tr>';
                                        
//           12                           <td title="'.$audit_result[$value['result']].'"><span class="txt-cut">'.$audit_result[$value['result']].'</span></td>

//                        $package = $value['package'];
//                        $provinceName=$package['provinceName'];
//                        $cityName=$package['cityName'];
//                        $result = $value['result'];
//                        $user = $value['user'];
//                        $str='审批完成';
//                        if($result['result']==1){
//                            $str='<span class="txt-cut approval"  application_id="'.$result['application_id'].'" result_id="'.$result['id'].'" >审批</span>';
//                        }
//                        echo ' <tr class="text-left" >
//                                            <td class="clearfix text-center" >'.$i.'</td>
//                                            <td title="">'.$package['code'].'</td>
//                                            <td title="'.$package['title'].'">'.$package['title'].'</td>
//                                            <td title="'.$package['principal'].'">'.$package['principal'].'</td>
//                                            <td title="">'.$provinceName['title'].$cityName['title'].'</td>
//                                            <td title="'.$user['realname'].'">'.$user['realname'].'</td>
//                                            <td title="'.$value['reason'].'"><span class="txt-cut">'.$value['reason'].'</span></td>
//                                            <td title="">'.$value['applied_at'].'</td>
//                                            <td title="">'.$audit_result[$result['result']].'</td>
//                                            <td title="'.$result['note'].'"><span class="txt-cut">'.$result['note'].'</span></td>
//                                            <td title="审批">'.$str.'</td>
//                                        </tr>';
                    }
                    ?>
                    </tbody>
                </table>
            </div>
            <div class="pagingBox">
                <?PHP
                echo LinkPager::widget([
                    'pagination' => $pages,
                    'firstPageLabel' => '首页',
                    'lastPageLabel' => '尾页',
                    'nextPageLabel' => '下一页',
                    'prevPageLabel' => '上一页'
                ]);
                ?>
            </div>
        <?PHP } ?>
    </div>
</div>
<script>
    /*立项审批 点击审批弹出模态框及填写显示信息*/
    $(".approval").click(function(){
        var objTr=$(this).parents("tr");
        $("#packageName").html(objTr.find("td").eq(2).attr("title"));
        $("#proposerUser").html(objTr.find("td").eq(4).attr("title"));
        $("#noteDetail").html(objTr.find("td").eq(5).attr("title"));
        $("#note").html(objTr.find("td").eq(8).attr("title"));
        $("#application_id").val($(this).attr("application_id"));
        $("#result_id").val($(this).attr("result_id"));
        $("#AssetPackageEditing-approval").modal();
    });
</script>